#pragma once
#include <MMSystem.h>
#include <boost/noncopyable.hpp>
#include <unordered_map>
#include "../sgp/TimerType.h"
#include "ImportExport.h"

namespace ja2{ namespace sgp
{
	//! Timer control.
	class TimerManager : boost::noncopyable
	{
		// Constants
	private:
		//! Base resolution for callback.
		static std::uint_least16_t const BASE_TIME_SLICE = 10;

		// Typedefs
	private:
		//! Timer map.
		typedef std::unordered_map<TimerType, std::uint_least32_t> TimerMap_t;

		// Attributes
	private:
		//! Clock Callback event ID.
		MMRESULT m_TimerId;
		//! Pause clock.
		bool m_PauseClock;
		//! Actual timer map.
		TimerMap_t m_TimerMap;
		//! Time passed without pause affection
		std::uint_least32_t m_NoPauseClock;
		//! Time passed (not counted if timer is paused).
		std::uint_least32_t m_Clock;

		// Operations
	public:
		//! Get actual clock value.
		JA2_SGP_API std::uint_least32_t get_clock() const;
	private:
		//! Get time interval.
		static std::uint_least32_t get_interval(TimerType Type);
		//! Timer callback.
		static void CALLBACK timer_callback(UINT TimerID, UINT Msg, DWORD_PTR pUser, DWORD_PTR dw1, DWORD_PTR dw2);
		//! Update counter.
		void update_counter(TimerType Timer);

		// Construction/Destruction
	public:
		JA2_SGP_API TimerManager();
		JA2_SGP_API ~TimerManager();
	};
} /*sgp*/} /*ja2*/
